package main

import (
	"os"

	"github.com/gamelife1314/logging"
)

var log = logging.GetDefaultLogger()

// mustSetLogging 设置日志记录器
func mustSetLogging() {
	logFile, err := os.OpenFile("main.log", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
	if err != nil {
		panic(err)
	}

	log = &logging.Logger{
		Level: logging.DEBUG,
		StreamHandler: &logging.StreamMessageHandler{
			Level: logging.INFO,
			Formatter: &logging.MessageFormatter{
				Format:     `{{.Color}}[{{.Time}}] {{.LevelString | printf "%8s"}} {{.ColorClear}} {{.Message}}`,
				TimeFormat: "15:04:05",
			},
			Destination: os.Stdout,
		},
		FileHandler: &logging.FileMessageHandler{
			Level: logging.DEBUG,
			Formatter: &logging.MessageFormatter{
				Format:     "[{{.Time}}] {{.LevelString}} {{.FuncName}} {{.ShortFileName}} {{.Line}} {{.Message}}\n",
				TimeFormat: "2006-01-02 15:04:05.999999",
			},
			Destination: logFile,
		},
	}
}
